package com.oreilly.hh;

import java.sql.Time;
import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.oreilly.hh.data.Track;

public class CreateTest {
	public static void main(String[] args) {
		Configuration config = new Configuration();
		config.configure();

		SessionFactory factory = config.buildSessionFactory();
		Session session = factory.openSession();
		Transaction tx = null;
		try {

			tx = session.beginTransaction();

			Track track = new Track("Russian Trance 2",
					"vol2/album610/track02.mp3", Time.valueOf("00:03:30"),
					new Date(), (short) 0);
			session.save(track);
			
			track = new Track("Video killed the radio star", "vol2/album611/track12.mp3",
					Time.valueOf("00:03:49"), new Date(), (short) 1);
			session.save(track);
			
			track = new Track("Gravity Angel", "vol2/album175/track03.mp3",
					Time.valueOf("00:06:06"), new Date(), (short) 1);
			session.save(track);
			
			
			tx.commit();
			
			tx = session.beginTransaction();
			Criteria crit = session.createCriteria(Track.class);
			List<Track> list = crit.list();
			
			for(Track tr : list){
				System.out.println(tr);
			}
			tx.commit();
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		factory.close();
	}
}
